package com.zk.mybatisplus;

import com.zk.mybatisplus.mapper.UserMapper;
import com.zk.mybatisplus.pojo.User;
import lombok.val;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class TestMybatis {
    @Autowired
    private UserMapper userMapper;
    @Test
    void contextLoads(){
        val users = userMapper.selectList(null);
        users.forEach(System.out::println);
    }
    @Test
    void updateLoads(){
        User user = new User();
        user.setId(8L);
        user.setAge(20);
        user.setName("ywbs22");
        System.out.print(userMapper.updateById(user));
    }
    @Test
    void insertLoads(){
        User user = new User();
        user.setAge(20);
        user.setName("ywbss111");
        System.out.print(userMapper.insert(user));
    }

    @Test
    void optimisiticClock(){
        User user = userMapper.selectById(1L);
        user.setName("zk");
        userMapper.updateById(user);
    }
    @Test
    void deleteTest(){
        userMapper.deleteById(1L);
    }
}
